﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using STLGROUP.Layers.Presentations;
using STLGROUP.Layers.ReportTemplates;
using STLGROUP.Layers.Common;

namespace QuanLyBanHang
{
    /// <summary>
    /// Xuat hoa don ban hang
    /// </summary>
    public partial class RF008 : frmReportBase
    {
        private int _iDHoaDon;

        public int IDHoaDon
        {
            get { return _iDHoaDon; }
            set { _iDHoaDon = value; }
        }

        public RF008()
        {
            InitializeComponent();
            this.Load += new EventHandler(RF008_Load);
        }

        private void RF008_Load(object sender, EventArgs e)
        {
            try
            {
                CR008_HoaDonBanSi rp = new CR008_HoaDonBanSi();

                var data = Cache.Context.View_HoaDon_CTHD.Where(s=>s.IDHoaDon==IDHoaDon).Select(s => new
                {
                    s.MaHoaDon,
                    s.MaNhanVien,
                    s.HoTenNhanVien,
                    s.SoDienThoai,
                    s.DiaChi,
                    s.MaKhachHang,
                    s.HoTenKhachHang,
                    s.SDTKhachHang,
                    s.DiaChiKhachHang,
                    s.MaSanPham,
                    s.TenSanPham,
                    s.SoLuong,
                    s.TongTien,
                    s.ConLai,
                    s.DaTra,
                    s.ThanhTienBanSi,
                    s.GiaBanSi,
                    s.SoTienGiam,
                    s.SoTienPhaiTra,
                });

                rp.SetDataSource(data);

                crystalReportViewer.ReportSource = rp;

            }
            catch (Exception ex)
            {
                UICommon.ShowMessgeString("Xảy ra lỗi trong quá trình xuất hóa đơn " + ex.Message, "Lỗi xuất report");
            }
        }

    }
}
